function [headers, abspos, relpos, chroms, chromEndSites, copydata] = readData(filename)
%UNTITLED Summary of this function goes here
%   Detailed explanation goes here

lineCount = 0;
F = fopen(filename);
while(fgets(F) ~= -1)
    lineCount = lineCount + 1;
end
fprintf('lines: %d\n', lineCount);

F = fopen(filename);
headersLine = fgets(F);
headersBig = strread(headersLine, '%s');
for i=4:size(headersBig, 1)
    headers{i - 3, 1} = headersBig{i, 1};
end

nextLine = fgets(F);
i = 1;
data = zeros(lineCount-1, size(headersBig, 1));
fprintf('data is %dx%d\n', size(data, 1), size(data, 2));
while (nextLine ~= -1)
    %fprintf('on line %d\n', i);
    next = strread(nextLine, '%f');
    %fprintf('next is %dx%d\n', size(next, 1), size(next, 2));
    data(i, :) = next;
    nextLine = fgets(F);
    i = i+1;
end
positions = zeros(lineCount-1, 1);
copydata = zeros(lineCount-1, size(headers, 1));
chromEndIdx = 0;
for i=1:size(data, 1)
    abspos(i, 1) = data(i, 3);
    relpos(i, 1) = data(i, 2);
    chroms(i, 1) = data(i, 1);
    if (i == size(data, 1) || data(i, 1) ~= data(i + 1, 1))
        chromEndIdx = chromEndIdx + 1;
        chromEndSites(chromEndIdx, 1) = i;
    end
    for j=4:size(data, 2)
        copydata(i, j-3) = data(i, j);
    end
end

copydata = copydata';
%copydata = copydata / max(max(copydata));

end

